<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//入职时间
			var induction=new Date("2012/06/30 8:45:25");
			//复制一个合同到期时间
			var resignation=new Date(induction);
			//设置3年后的时间
			resignation.setFullYear(resignation.getFullYear()+3);
			console.log("您入职的时间为"+induction);
			console.log("您合同到期的时间为"+resignation);
			
			//合同到期的前一个月要续约
			var moretime=new Date(resignation);
			moretime.setMonth(moretime.getMonth()-1);
			
			//判断这一天是不是周末
			if(moretime.getDay()==6){
				moretime.setDate(moretime.getDate()-1);
			}else if(moretime.getDay()==0){
				moretime.setDate(moretime.getDate()-2);
			}
			
			//续约前的一周
			var tips=new Date(moretime);
			tips.setDate(tips.getDate()-7);
			
			//自定义一个format函数来显示结果
			
			function format(date){
				var years=date.getFullYear();
				var months=date.getMonth()+1;
				var day=date.getDate();
				var week=date.getDay();
				
				var hours=date.getHours();
				var minutes=date.getMinutes();
				var seconds=date.getSeconds();
				
				hours<10&&(hours="0"+hours);
				minutes<10&&(minutes="0"+minutes);
				seconds<10&&(seconds="0"+seconds);
				var apm="";
				var weeks=["日","一","二","三","四","五","六",];
				if(hours<12){
					apm="上午";
				}else{
					apm="下午";
				}
				
				return years+"年"+months+"月"+day+"日  星期"+weeks[week]+" "+apm+hours+":"+minutes+":"+seconds;
				
			}
			
			console.log(format(induction));
			console.log(format(resignation));
			console.log(format(moretime));
			console.log(format(tips));
			
			
		</script>
	</body>
</html>
